package com.wyw.hemerocallis.handler;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import com.wyw.hemerocallis.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;

/**
 * 自定义通用的限流处理逻辑
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@Slf4j
public class WywBlockHandler {

    /**
     * 通用限流处理方法
     * 这个方法必须是 static 的
     * @param exception
     * @return
     */
    public static CommonResponse<String> wywHandlerBlockException(BlockException exception) {

        log.error("trigger wyw block handler: [{}], [{}]",
                JSON.toJSONString(exception.getRule()), exception.getRuleLimitApp());
        return new CommonResponse<>(
                "4000",
                "flow rule trigger block exception",
                null
        );
    }
}
